package com.mypg;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class NewsHelper {
    private int news_id;
    private String news_title;
    private String news_content;
    private String news_img;
    private String news_time;
    private String news_class;

    public static NewsHelper changeNewsToNewsHelper(News news){
        NewsHelper newsHelper=new NewsHelper();
        newsHelper.setNews_id(news.getNews_id());
        newsHelper.setNews_title(news.getNews_title());
        newsHelper.setNews_content(news.getNews_content());
        newsHelper.setNews_img(news.getNews_img());
        SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String time_str=df.format(news.getNews_time().getTime());
        newsHelper.setNews_time(time_str);
        newsHelper.setNews_class(news.getNews_class());
        return newsHelper;
    }

    public static List<NewsHelper> changeNewsListToNewsHelperList(List<News> newsList){
        List<NewsHelper> newsHelperList=new ArrayList<>();
        for(int i=0;i<newsList.size();i++){
            newsHelperList.add(NewsHelper.changeNewsToNewsHelper(newsList.get(i)));
        }
        return newsHelperList;
    }

    public NewsHelper(){}
    public NewsHelper(int news_id, String news_title, String news_content, String news_img, String news_time, String news_class) {
        this.news_id = news_id;
        this.news_title = news_title;
        this.news_content = news_content;
        this.news_img = news_img;
        this.news_time = news_time;
        this.news_class = news_class;
    }

    public int getNews_id() {
        return news_id;
    }

    public void setNews_id(int news_id) {
        this.news_id = news_id;
    }

    public String getNews_title() {
        return news_title;
    }

    public void setNews_title(String news_title) {
        this.news_title = news_title;
    }

    public String getNews_content() {
        return news_content;
    }

    public void setNews_content(String news_content) {
        this.news_content = news_content;
    }

    public String getNews_img() {
        return news_img;
    }

    public void setNews_img(String news_img) {
        this.news_img = news_img;
    }

    public String getNews_time() {
        return news_time;
    }

    public void setNews_time(String news_time) {
        this.news_time = news_time;
    }

    public String getNews_class() {
        return news_class;
    }

    public void setNews_class(String news_class) {
        this.news_class = news_class;
    }

    @Override
    public String toString() {
        return "NewsHelper{" +
                "news_id=" + news_id +
                ", news_title='" + news_title + '\'' +
                ", news_content='" + news_content + '\'' +
                ", news_img='" + news_img + '\'' +
                ", news_time='" + news_time + '\'' +
                ", news_class='" + news_class + '\'' +
                '}';
    }
}
